/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package vn.com.fis.portal.vtcc.service;

import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.model.BaseModel;

import vn.com.fis.portal.vtcc.model.SampleEntryClp;
import vn.com.fis.portal.vtcc.model.StrainEntryClp;

import java.lang.reflect.Method;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Brian Wing Shun Chan
 */
public class ClpSerializer {
	public static String getServletContextName() {
		if (Validator.isNotNull(_servletContextName)) {
			return _servletContextName;
		}

		synchronized (ClpSerializer.class) {
			if (Validator.isNotNull(_servletContextName)) {
				return _servletContextName;
			}

			try {
				ClassLoader classLoader = ClpSerializer.class.getClassLoader();

				Class<?> portletPropsClass = classLoader.loadClass(
						"com.liferay.util.portlet.PortletProps");

				Method getMethod = portletPropsClass.getMethod("get",
						new Class<?>[] { String.class });

				String portletPropsServletContextName = (String)getMethod.invoke(null,
						"VTCC-portlet-deployment-context");

				if (Validator.isNotNull(portletPropsServletContextName)) {
					_servletContextName = portletPropsServletContextName;
				}
			}
			catch (Throwable t) {
				if (_log.isInfoEnabled()) {
					_log.info(
						"Unable to locate deployment context from portlet properties");
				}
			}

			if (Validator.isNull(_servletContextName)) {
				try {
					String propsUtilServletContextName = PropsUtil.get(
							"VTCC-portlet-deployment-context");

					if (Validator.isNotNull(propsUtilServletContextName)) {
						_servletContextName = propsUtilServletContextName;
					}
				}
				catch (Throwable t) {
					if (_log.isInfoEnabled()) {
						_log.info(
							"Unable to locate deployment context from portal properties");
					}
				}
			}

			if (Validator.isNull(_servletContextName)) {
				_servletContextName = "VTCC-portlet";
			}

			return _servletContextName;
		}
	}

	public static void setClassLoader(ClassLoader classLoader) {
		_classLoader = classLoader;
	}

	public static Object translateInput(BaseModel<?> oldModel) {
		Class<?> oldModelClass = oldModel.getClass();

		String oldModelClassName = oldModelClass.getName();

		if (oldModelClassName.equals(SampleEntryClp.class.getName())) {
			return translateInputSampleEntry(oldModel);
		}

		if (oldModelClassName.equals(StrainEntryClp.class.getName())) {
			return translateInputStrainEntry(oldModel);
		}

		return oldModel;
	}

	public static Object translateInput(List<Object> oldList) {
		List<Object> newList = new ArrayList<Object>(oldList.size());

		for (int i = 0; i < oldList.size(); i++) {
			Object curObj = oldList.get(i);

			newList.add(translateInput(curObj));
		}

		return newList;
	}

	public static Object translateInputSampleEntry(BaseModel<?> oldModel) {
		SampleEntryClp oldCplModel = (SampleEntryClp)oldModel;

		Thread currentThread = Thread.currentThread();

		ClassLoader contextClassLoader = currentThread.getContextClassLoader();

		try {
			currentThread.setContextClassLoader(_classLoader);

			try {
				Class<?> newModelClass = Class.forName("vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl",
						true, _classLoader);

				Object newModel = newModelClass.newInstance();

				Method method0 = newModelClass.getMethod("setSampleId",
						new Class[] { Long.TYPE });

				Long value0 = new Long(oldCplModel.getSampleId());

				method0.invoke(newModel, value0);

				Method method1 = newModelClass.getMethod("setScientificName",
						new Class[] { String.class });

				String value1 = oldCplModel.getScientificName();

				method1.invoke(newModel, value1);

				Method method2 = newModelClass.getMethod("setSampleSynonym",
						new Class[] { String.class });

				String value2 = oldCplModel.getSampleSynonym();

				method2.invoke(newModel, value2);

				Method method3 = newModelClass.getMethod("setECatalog",
						new Class[] { Integer.TYPE });

				Integer value3 = new Integer(oldCplModel.getECatalog());

				method3.invoke(newModel, value3);

				Method method4 = newModelClass.getMethod("setSampleCode",
						new Class[] { String.class });

				String value4 = oldCplModel.getSampleCode();

				method4.invoke(newModel, value4);

				Method method5 = newModelClass.getMethod("setCatalogYear",
						new Class[] { String.class });

				String value5 = oldCplModel.getCatalogYear();

				method5.invoke(newModel, value5);

				Method method6 = newModelClass.getMethod("setOtherName",
						new Class[] { String.class });

				String value6 = oldCplModel.getOtherName();

				method6.invoke(newModel, value6);

				Method method7 = newModelClass.getMethod("setSampleOtherCode",
						new Class[] { String.class });

				String value7 = oldCplModel.getSampleOtherCode();

				method7.invoke(newModel, value7);

				Method method8 = newModelClass.getMethod("setSourceIsolation",
						new Class[] { String.class });

				String value8 = oldCplModel.getSourceIsolation();

				method8.invoke(newModel, value8);

				Method method9 = newModelClass.getMethod("setHistory",
						new Class[] { String.class });

				String value9 = oldCplModel.getHistory();

				method9.invoke(newModel, value9);

				Method method10 = newModelClass.getMethod("setSampleForeign",
						new Class[] { Integer.TYPE });

				Integer value10 = new Integer(oldCplModel.getSampleForeign());

				method10.invoke(newModel, value10);

				Method method11 = newModelClass.getMethod("setDomestic",
						new Class[] { Integer.TYPE });

				Integer value11 = new Integer(oldCplModel.getDomestic());

				method11.invoke(newModel, value11);

				Method method12 = newModelClass.getMethod("setDeposit",
						new Class[] { Integer.TYPE });

				Integer value12 = new Integer(oldCplModel.getDeposit());

				method12.invoke(newModel, value12);

				Method method13 = newModelClass.getMethod("setIsolationMethod",
						new Class[] { String.class });

				String value13 = oldCplModel.getIsolationMethod();

				method13.invoke(newModel, value13);

				Method method14 = newModelClass.getMethod("setIsolationTime",
						new Class[] { String.class });

				String value14 = oldCplModel.getIsolationTime();

				method14.invoke(newModel, value14);

				Method method15 = newModelClass.getMethod("setDepositionTime",
						new Class[] { String.class });

				String value15 = oldCplModel.getDepositionTime();

				method15.invoke(newModel, value15);

				Method method16 = newModelClass.getMethod("setIsolationPerson",
						new Class[] { String.class });

				String value16 = oldCplModel.getIsolationPerson();

				method16.invoke(newModel, value16);

				Method method17 = newModelClass.getMethod("setFd",
						new Class[] { String.class });

				String value17 = oldCplModel.getFd();

				method17.invoke(newModel, value17);

				Method method18 = newModelClass.getMethod("setDf",
						new Class[] { String.class });

				String value18 = oldCplModel.getDf();

				method18.invoke(newModel, value18);

				Method method19 = newModelClass.getMethod("setSampleLN",
						new Class[] { String.class });

				String value19 = oldCplModel.getSampleLN();

				method19.invoke(newModel, value19);

				Method method20 = newModelClass.getMethod("setCultivationMedium",
						new Class[] { String.class });

				String value20 = oldCplModel.getCultivationMedium();

				method20.invoke(newModel, value20);

				Method method21 = newModelClass.getMethod("setCultivationTemperature",
						new Class[] { String.class });

				String value21 = oldCplModel.getCultivationTemperature();

				method21.invoke(newModel, value21);

				Method method22 = newModelClass.getMethod("setPH",
						new Class[] { String.class });

				String value22 = oldCplModel.getPH();

				method22.invoke(newModel, value22);

				Method method23 = newModelClass.getMethod("setMostRecentCheckingDate",
						new Class[] { Date.class });

				Date value23 = oldCplModel.getMostRecentCheckingDate();

				method23.invoke(newModel, value23);

				Method method24 = newModelClass.getMethod("setSurvivability",
						new Class[] { String.class });

				String value24 = oldCplModel.getSurvivability();

				method24.invoke(newModel, value24);

				Method method25 = newModelClass.getMethod("setTypeStrain",
						new Class[] { Integer.TYPE });

				Integer value25 = new Integer(oldCplModel.getTypeStrain());

				method25.invoke(newModel, value25);

				Method method26 = newModelClass.getMethod("setNaturalStrain",
						new Class[] { Integer.TYPE });

				Integer value26 = new Integer(oldCplModel.getNaturalStrain());

				method26.invoke(newModel, value26);

				Method method27 = newModelClass.getMethod("setMutatedStrain",
						new Class[] { Integer.TYPE });

				Integer value27 = new Integer(oldCplModel.getMutatedStrain());

				method27.invoke(newModel, value27);

				Method method28 = newModelClass.getMethod("setProductionStrain",
						new Class[] { Integer.TYPE });

				Integer value28 = new Integer(oldCplModel.getProductionStrain());

				method28.invoke(newModel, value28);

				Method method29 = newModelClass.getMethod("setCellMorphology",
						new Class[] { String.class });

				String value29 = oldCplModel.getCellMorphology();

				method29.invoke(newModel, value29);

				Method method30 = newModelClass.getMethod("setCellPhoto",
						new Class[] { String.class });

				String value30 = oldCplModel.getCellPhoto();

				method30.invoke(newModel, value30);

				Method method31 = newModelClass.getMethod("setColonyPhoto",
						new Class[] { String.class });

				String value31 = oldCplModel.getColonyPhoto();

				method31.invoke(newModel, value31);

				Method method32 = newModelClass.getMethod("setSporePhoto",
						new Class[] { String.class });

				String value32 = oldCplModel.getSporePhoto();

				method32.invoke(newModel, value32);

				Method method33 = newModelClass.getMethod("setSequences",
						new Class[] { String.class });

				String value33 = oldCplModel.getSequences();

				method33.invoke(newModel, value33);

				Method method34 = newModelClass.getMethod("setGrowthCondition",
						new Class[] { String.class });

				String value34 = oldCplModel.getGrowthCondition();

				method34.invoke(newModel, value34);

				Method method35 = newModelClass.getMethod("setQuinone",
						new Class[] { String.class });

				String value35 = oldCplModel.getQuinone();

				method35.invoke(newModel, value35);

				Method method36 = newModelClass.getMethod("setGCContent",
						new Class[] { String.class });

				String value36 = oldCplModel.getGCContent();

				method36.invoke(newModel, value36);

				Method method37 = newModelClass.getMethod("setOtherCharacteristics",
						new Class[] { String.class });

				String value37 = oldCplModel.getOtherCharacteristics();

				method37.invoke(newModel, value37);

				Method method38 = newModelClass.getMethod("setApplications",
						new Class[] { String.class });

				String value38 = oldCplModel.getApplications();

				method38.invoke(newModel, value38);

				Method method39 = newModelClass.getMethod("setSampleReferences",
						new Class[] { String.class });

				String value39 = oldCplModel.getSampleReferences();

				method39.invoke(newModel, value39);

				Method method40 = newModelClass.getMethod("setCreateDate",
						new Class[] { Date.class });

				Date value40 = oldCplModel.getCreateDate();

				method40.invoke(newModel, value40);

				Method method41 = newModelClass.getMethod("setUpdateDate",
						new Class[] { Date.class });

				Date value41 = oldCplModel.getUpdateDate();

				method41.invoke(newModel, value41);

				Method method42 = newModelClass.getMethod("setBiosafety",
						new Class[] { String.class });

				String value42 = oldCplModel.getBiosafety();

				method42.invoke(newModel, value42);

				Method method43 = newModelClass.getMethod("setStatus",
						new Class[] { Integer.TYPE });

				Integer value43 = new Integer(oldCplModel.getStatus());

				method43.invoke(newModel, value43);

				Method method44 = newModelClass.getMethod("setStrainId",
						new Class[] { Long.TYPE });

				Long value44 = new Long(oldCplModel.getStrainId());

				method44.invoke(newModel, value44);

				return newModel;
			}
			catch (Exception e) {
				_log.error(e, e);
			}
		}
		finally {
			currentThread.setContextClassLoader(contextClassLoader);
		}

		return oldModel;
	}

	public static Object translateInputStrainEntry(BaseModel<?> oldModel) {
		StrainEntryClp oldCplModel = (StrainEntryClp)oldModel;

		Thread currentThread = Thread.currentThread();

		ClassLoader contextClassLoader = currentThread.getContextClassLoader();

		try {
			currentThread.setContextClassLoader(_classLoader);

			try {
				Class<?> newModelClass = Class.forName("vn.com.fis.portal.vtcc.model.impl.StrainEntryImpl",
						true, _classLoader);

				Object newModel = newModelClass.newInstance();

				Method method0 = newModelClass.getMethod("setStrainId",
						new Class[] { Long.TYPE });

				Long value0 = new Long(oldCplModel.getStrainId());

				method0.invoke(newModel, value0);

				Method method1 = newModelClass.getMethod("setStrainName",
						new Class[] { String.class });

				String value1 = oldCplModel.getStrainName();

				method1.invoke(newModel, value1);

				Method method2 = newModelClass.getMethod("setDescription",
						new Class[] { String.class });

				String value2 = oldCplModel.getDescription();

				method2.invoke(newModel, value2);

				Method method3 = newModelClass.getMethod("setStatus",
						new Class[] { Integer.TYPE });

				Integer value3 = new Integer(oldCplModel.getStatus());

				method3.invoke(newModel, value3);

				Method method4 = newModelClass.getMethod("setSampleId",
						new Class[] { Integer.TYPE });

				Integer value4 = new Integer(oldCplModel.getSampleId());

				method4.invoke(newModel, value4);

				return newModel;
			}
			catch (Exception e) {
				_log.error(e, e);
			}
		}
		finally {
			currentThread.setContextClassLoader(contextClassLoader);
		}

		return oldModel;
	}

	public static Object translateInput(Object obj) {
		if (obj instanceof BaseModel<?>) {
			return translateInput((BaseModel<?>)obj);
		}
		else if (obj instanceof List<?>) {
			return translateInput((List<Object>)obj);
		}
		else {
			return obj;
		}
	}

	public static Object translateOutput(BaseModel<?> oldModel) {
		Class<?> oldModelClass = oldModel.getClass();

		String oldModelClassName = oldModelClass.getName();

		if (oldModelClassName.equals(
					"vn.com.fis.portal.vtcc.model.impl.SampleEntryImpl")) {
			return translateOutputSampleEntry(oldModel);
		}

		if (oldModelClassName.equals(
					"vn.com.fis.portal.vtcc.model.impl.StrainEntryImpl")) {
			return translateOutputStrainEntry(oldModel);
		}

		return oldModel;
	}

	public static Object translateOutput(List<Object> oldList) {
		List<Object> newList = new ArrayList<Object>(oldList.size());

		for (int i = 0; i < oldList.size(); i++) {
			Object curObj = oldList.get(i);

			newList.add(translateOutput(curObj));
		}

		return newList;
	}

	public static Object translateOutput(Object obj) {
		if (obj instanceof BaseModel<?>) {
			return translateOutput((BaseModel<?>)obj);
		}
		else if (obj instanceof List<?>) {
			return translateOutput((List<Object>)obj);
		}
		else {
			return obj;
		}
	}

	public static Object translateOutputSampleEntry(BaseModel<?> oldModel) {
		Thread currentThread = Thread.currentThread();

		ClassLoader contextClassLoader = currentThread.getContextClassLoader();

		try {
			currentThread.setContextClassLoader(_classLoader);

			try {
				SampleEntryClp newModel = new SampleEntryClp();

				Class<?> oldModelClass = oldModel.getClass();

				Method method0 = oldModelClass.getMethod("getSampleId");

				Long value0 = (Long)method0.invoke(oldModel, (Object[])null);

				newModel.setSampleId(value0);

				Method method1 = oldModelClass.getMethod("getScientificName");

				String value1 = (String)method1.invoke(oldModel, (Object[])null);

				newModel.setScientificName(value1);

				Method method2 = oldModelClass.getMethod("getSampleSynonym");

				String value2 = (String)method2.invoke(oldModel, (Object[])null);

				newModel.setSampleSynonym(value2);

				Method method3 = oldModelClass.getMethod("getECatalog");

				Integer value3 = (Integer)method3.invoke(oldModel,
						(Object[])null);

				newModel.setECatalog(value3);

				Method method4 = oldModelClass.getMethod("getSampleCode");

				String value4 = (String)method4.invoke(oldModel, (Object[])null);

				newModel.setSampleCode(value4);

				Method method5 = oldModelClass.getMethod("getCatalogYear");

				String value5 = (String)method5.invoke(oldModel, (Object[])null);

				newModel.setCatalogYear(value5);

				Method method6 = oldModelClass.getMethod("getOtherName");

				String value6 = (String)method6.invoke(oldModel, (Object[])null);

				newModel.setOtherName(value6);

				Method method7 = oldModelClass.getMethod("getSampleOtherCode");

				String value7 = (String)method7.invoke(oldModel, (Object[])null);

				newModel.setSampleOtherCode(value7);

				Method method8 = oldModelClass.getMethod("getSourceIsolation");

				String value8 = (String)method8.invoke(oldModel, (Object[])null);

				newModel.setSourceIsolation(value8);

				Method method9 = oldModelClass.getMethod("getHistory");

				String value9 = (String)method9.invoke(oldModel, (Object[])null);

				newModel.setHistory(value9);

				Method method10 = oldModelClass.getMethod("getSampleForeign");

				Integer value10 = (Integer)method10.invoke(oldModel,
						(Object[])null);

				newModel.setSampleForeign(value10);

				Method method11 = oldModelClass.getMethod("getDomestic");

				Integer value11 = (Integer)method11.invoke(oldModel,
						(Object[])null);

				newModel.setDomestic(value11);

				Method method12 = oldModelClass.getMethod("getDeposit");

				Integer value12 = (Integer)method12.invoke(oldModel,
						(Object[])null);

				newModel.setDeposit(value12);

				Method method13 = oldModelClass.getMethod("getIsolationMethod");

				String value13 = (String)method13.invoke(oldModel,
						(Object[])null);

				newModel.setIsolationMethod(value13);

				Method method14 = oldModelClass.getMethod("getIsolationTime");

				String value14 = (String)method14.invoke(oldModel,
						(Object[])null);

				newModel.setIsolationTime(value14);

				Method method15 = oldModelClass.getMethod("getDepositionTime");

				String value15 = (String)method15.invoke(oldModel,
						(Object[])null);

				newModel.setDepositionTime(value15);

				Method method16 = oldModelClass.getMethod("getIsolationPerson");

				String value16 = (String)method16.invoke(oldModel,
						(Object[])null);

				newModel.setIsolationPerson(value16);

				Method method17 = oldModelClass.getMethod("getFd");

				String value17 = (String)method17.invoke(oldModel,
						(Object[])null);

				newModel.setFd(value17);

				Method method18 = oldModelClass.getMethod("getDf");

				String value18 = (String)method18.invoke(oldModel,
						(Object[])null);

				newModel.setDf(value18);

				Method method19 = oldModelClass.getMethod("getSampleLN");

				String value19 = (String)method19.invoke(oldModel,
						(Object[])null);

				newModel.setSampleLN(value19);

				Method method20 = oldModelClass.getMethod(
						"getCultivationMedium");

				String value20 = (String)method20.invoke(oldModel,
						(Object[])null);

				newModel.setCultivationMedium(value20);

				Method method21 = oldModelClass.getMethod(
						"getCultivationTemperature");

				String value21 = (String)method21.invoke(oldModel,
						(Object[])null);

				newModel.setCultivationTemperature(value21);

				Method method22 = oldModelClass.getMethod("getPH");

				String value22 = (String)method22.invoke(oldModel,
						(Object[])null);

				newModel.setPH(value22);

				Method method23 = oldModelClass.getMethod(
						"getMostRecentCheckingDate");

				Date value23 = (Date)method23.invoke(oldModel, (Object[])null);

				newModel.setMostRecentCheckingDate(value23);

				Method method24 = oldModelClass.getMethod("getSurvivability");

				String value24 = (String)method24.invoke(oldModel,
						(Object[])null);

				newModel.setSurvivability(value24);

				Method method25 = oldModelClass.getMethod("getTypeStrain");

				Integer value25 = (Integer)method25.invoke(oldModel,
						(Object[])null);

				newModel.setTypeStrain(value25);

				Method method26 = oldModelClass.getMethod("getNaturalStrain");

				Integer value26 = (Integer)method26.invoke(oldModel,
						(Object[])null);

				newModel.setNaturalStrain(value26);

				Method method27 = oldModelClass.getMethod("getMutatedStrain");

				Integer value27 = (Integer)method27.invoke(oldModel,
						(Object[])null);

				newModel.setMutatedStrain(value27);

				Method method28 = oldModelClass.getMethod("getProductionStrain");

				Integer value28 = (Integer)method28.invoke(oldModel,
						(Object[])null);

				newModel.setProductionStrain(value28);

				Method method29 = oldModelClass.getMethod("getCellMorphology");

				String value29 = (String)method29.invoke(oldModel,
						(Object[])null);

				newModel.setCellMorphology(value29);

				Method method30 = oldModelClass.getMethod("getCellPhoto");

				String value30 = (String)method30.invoke(oldModel,
						(Object[])null);

				newModel.setCellPhoto(value30);

				Method method31 = oldModelClass.getMethod("getColonyPhoto");

				String value31 = (String)method31.invoke(oldModel,
						(Object[])null);

				newModel.setColonyPhoto(value31);

				Method method32 = oldModelClass.getMethod("getSporePhoto");

				String value32 = (String)method32.invoke(oldModel,
						(Object[])null);

				newModel.setSporePhoto(value32);

				Method method33 = oldModelClass.getMethod("getSequences");

				String value33 = (String)method33.invoke(oldModel,
						(Object[])null);

				newModel.setSequences(value33);

				Method method34 = oldModelClass.getMethod("getGrowthCondition");

				String value34 = (String)method34.invoke(oldModel,
						(Object[])null);

				newModel.setGrowthCondition(value34);

				Method method35 = oldModelClass.getMethod("getQuinone");

				String value35 = (String)method35.invoke(oldModel,
						(Object[])null);

				newModel.setQuinone(value35);

				Method method36 = oldModelClass.getMethod("getGCContent");

				String value36 = (String)method36.invoke(oldModel,
						(Object[])null);

				newModel.setGCContent(value36);

				Method method37 = oldModelClass.getMethod(
						"getOtherCharacteristics");

				String value37 = (String)method37.invoke(oldModel,
						(Object[])null);

				newModel.setOtherCharacteristics(value37);

				Method method38 = oldModelClass.getMethod("getApplications");

				String value38 = (String)method38.invoke(oldModel,
						(Object[])null);

				newModel.setApplications(value38);

				Method method39 = oldModelClass.getMethod("getSampleReferences");

				String value39 = (String)method39.invoke(oldModel,
						(Object[])null);

				newModel.setSampleReferences(value39);

				Method method40 = oldModelClass.getMethod("getCreateDate");

				Date value40 = (Date)method40.invoke(oldModel, (Object[])null);

				newModel.setCreateDate(value40);

				Method method41 = oldModelClass.getMethod("getUpdateDate");

				Date value41 = (Date)method41.invoke(oldModel, (Object[])null);

				newModel.setUpdateDate(value41);

				Method method42 = oldModelClass.getMethod("getBiosafety");

				String value42 = (String)method42.invoke(oldModel,
						(Object[])null);

				newModel.setBiosafety(value42);

				Method method43 = oldModelClass.getMethod("getStatus");

				Integer value43 = (Integer)method43.invoke(oldModel,
						(Object[])null);

				newModel.setStatus(value43);

				Method method44 = oldModelClass.getMethod("getStrainId");

				Long value44 = (Long)method44.invoke(oldModel, (Object[])null);

				newModel.setStrainId(value44);

				return newModel;
			}
			catch (Exception e) {
				_log.error(e, e);
			}
		}
		finally {
			currentThread.setContextClassLoader(contextClassLoader);
		}

		return oldModel;
	}

	public static Object translateOutputStrainEntry(BaseModel<?> oldModel) {
		Thread currentThread = Thread.currentThread();

		ClassLoader contextClassLoader = currentThread.getContextClassLoader();

		try {
			currentThread.setContextClassLoader(_classLoader);

			try {
				StrainEntryClp newModel = new StrainEntryClp();

				Class<?> oldModelClass = oldModel.getClass();

				Method method0 = oldModelClass.getMethod("getStrainId");

				Long value0 = (Long)method0.invoke(oldModel, (Object[])null);

				newModel.setStrainId(value0);

				Method method1 = oldModelClass.getMethod("getStrainName");

				String value1 = (String)method1.invoke(oldModel, (Object[])null);

				newModel.setStrainName(value1);

				Method method2 = oldModelClass.getMethod("getDescription");

				String value2 = (String)method2.invoke(oldModel, (Object[])null);

				newModel.setDescription(value2);

				Method method3 = oldModelClass.getMethod("getStatus");

				Integer value3 = (Integer)method3.invoke(oldModel,
						(Object[])null);

				newModel.setStatus(value3);

				Method method4 = oldModelClass.getMethod("getSampleId");

				Integer value4 = (Integer)method4.invoke(oldModel,
						(Object[])null);

				newModel.setSampleId(value4);

				return newModel;
			}
			catch (Exception e) {
				_log.error(e, e);
			}
		}
		finally {
			currentThread.setContextClassLoader(contextClassLoader);
		}

		return oldModel;
	}

	private static Log _log = LogFactoryUtil.getLog(ClpSerializer.class);
	private static ClassLoader _classLoader;
	private static String _servletContextName;
}